home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-05-25 | 4.0 KB | 140 lines | [TEXT/MPS ] |
- ;=====================================================================
- ;
- ; Copyright Apple Computer, Inc. 1986,1995
- ; All Rights Reserved
- ;
- ;=====================================================================
- ;
- ; File : CRCCalc.a
- ; Author : xxxxxx xxxxxx, July 30, 1986.
- ; Description : This file contains the CRC calculation.
- ; Revised : 05/25/95 fixed typo in word "incorporated", updated
- ; copyright date
- ; 10/29/92 incorporated Paul G's fix for ROM size
- ; up to 2Gbytes. Thanks, Paul!
- ;
- ;
- ;=====================================================================
-
- ;=====================================================================
- ; Initial Assembler Directives
- ;=====================================================================
- ;Include files
- INCLUDE 'SysEQU.a'
- INCLUDE 'ROMEqu.a' ;Declaration ROM EQU's
- INCLUDE 'SlotEqu.a'
-
- ;=====================================================================
- ; _CalcCRC : Calculate CRC
- ;
- ; PROCEDURE _CalcCRC(SizeCode,DataPtr,crc);
- ;=====================================================================
- _CalcCRC PROC EXPORT
-
- ;VAR
- RetnAddr$a EQU A0
- DataPtr$a EQU A1
- crcAdrL$a EQU A2
- crcAdrH$a EQU A3
- Temp$a EQU A4
- TopOfData$a EQU A5
-
- SizeCode$d EQU D0
- crcPos$d EQU D1
- crc$d EQU D2
- Temp$d EQU D3
- Index$d EQU D4
-
- ; Define stack-frame
- StackFrame RECORD {A6Link},DECR
- SizeCode DS.L 1 ;size of code
- DataPtr DS.L 1 ;pointer to data
- crc@ DS.L 1 ;VAR crc:longint
- Return DS.L 1 ;Return address
- A6Link DS.L 1 ;Old A6
- ENDR
-
- ; Other
- dataPtr EQU $4 ; [handle]
-
- ;----------------------------------------------------------------------
- ; _CalcCRC
- ;----------------------------------------------------------------------
- ;BEGIN
- ;;;;; WITH VDPageInfo, SlotIntQElement
- WITH FHeaderRec, StackFrame
-
- ; Allocate local vars
- LINK A6,#0
- MOVEM.L A2-A5/D3-D4,-(SP) ;Save registers
-
-
- ; Calculate the address of the crc value.
- MOVE.L SizeCode(A6),TopOfData$a ;TopOfData$a := Top of data
- ADD.L DataPtr(A6),TopOfData$a
-
- MOVE.L TopOfData$a,crcAdrL$a ;crcAdrL$a := TopOfData$a - (fhBlockSize-FH_crc) {Addr of crc MSB}
- SUB.L #fhBlockSize-fhCRC,crcAdrL$a
- MOVE.L crcAdrL$a,crcAdrH$a
- ADD.L #3,crcAdrH$a ;Addr of crc LSB
-
-
- ; Determine the size of the declaration data to be checked.
- MOVE.L TopOfData$a,Temp$a ;Temp$a := TopOfData$a - (fhBlockSize-FH_Length) {Addr of Length field}
- SUB.L #fhBlockSize-fhLength,Temp$a ;Index := length of crc data.
- MOVE.L (Temp$a),Index$d
- SUBQ.L #1,Index$d ;Adjust index for DBF
-
- MOVEQ #0,crc$d ;crc$d := 0
- MOVE.L DataPtr(A6),DataPtr$a ;DataPtr$a := pointer to data
-
- MOVE.L SizeCode(A6),Temp$d ;Adjust DataPtr$a
- SUB.L Index$d,Temp$d
- ADD.L Temp$d,DataPtr$a
- SUB.L #1,DataPtr$a
-
-
- ; Calc the crc value.
- MOVEQ #0,Temp$d ;Temp$d := 0
-
- ;REPEAT
- Repeat ROL.L #1,crc$d ; Rotate-left the crc value.
-
- CMP.L crcAdrL$a,DataPtr$a ; IF DataPtr$a IN [crcAdrL$a..crcAdrH$a] THEN
- BLT.S C10
- CMP.L crcAdrH$a,DataPtr$a
- BGT.S C10
-
- ADDQ.L #1,DataPtr$a ; DataPtr$a := DataPtr$a + 1 {Do not include crc in calculation}
- BRA.S Until
- ; ELSE
- C10 MOVE.B (DataPtr$a)+,Temp$d ; Temp$d := DataPtr$a^; DataPtr$a := DataPtr$a + 1
- ADD.L Temp$d,crc$d ; crc$d := crc$d + Temp$d
-
- Until
- ;!pg 1/27/92
- ;! DBF Index$d,Repeat
- subq.l #1,Index$d ;!pg 1/27/92 ;Index$d-=1
- bpl.s Repeat ;!pg 1/27/92 ;UNTIL Index$d < 0
-
- ; Patch in the crc result.
- MOVE.L crc$d,(crcAdrL$a)
-
-
- ; Move crc result to calling routine.
- MOVE.L crc@(A6),Temp$a
- MOVE.L crc$d,(Temp$a)
-
-
- ; Restore globals, cleanup stack & return
- End MOVEM.L (SP)+,A2-A5/D3-D4 ;Restore registers
- UNLK A6 ;Clear stack frame of local vars
- MOVE.L (SP)+,RetnAddr$a ;Remove return address
- ADD.L #12,SP ;Clear stack-frame of parameters
- JMP (RetnAddr$a) ;Return
-
- ENDWITH
-
- ENDP
-
- END